//index.js
//获取应用实例

const app = getApp()
const {
  apiUrl
} = getApp().globalData;
import { getZ } from "../../http/interface.js"

Page({
  data: {
    userInfo: {},
    banner: [],
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 2000,
    duration: 500,
    zhan:"",
    content:"",
    apiUrl:apiUrl,
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  goSite(){
    wx.switchTab({
      url: '/pages/map/index',
    })
  },
  goJing(){
    wx.navigateTo({
      url: '/pages/jing/index',
    })
  },
  goSite(){
    wx.navigateTo({
      url: '/pages/site/index',
    })
  },
  goInfo(){
    wx.navigateTo({
      url: '/pages/info/index',
    })
  },
  goYue(){
    if (!this.data.hasUserInfo){
      wx.navigateTo({
        url: '/pages/login/index?type=1',
      })
    }else{
      wx.navigateTo({
        url: '/pages/web/index?type=1',
      })
    }
  },
  getZhan(){
    getZ().then(res=>{
      this.setData({
        zhan:res.data,
        content:res.data.content
      })
    })
  },
  goZhan(){
    if (!this.data.hasUserInfo) {
      wx.navigateTo({
        url: '/pages/login/index?type=2',
      })
    } else {
      wx.navigateTo({
        url: '/pages/web/index?type=2',
      })
    }
  },
  goDetail(){
    wx.navigateTo({
      url: '/pages/detail/index',
    })
  },
   /**
     * @地图缩放
     */
    movablescale(e) {
      var that = this;
      let aa = 1 / e.detail.scale
      that.setData({
          scaleOld: aa
      })
  },
  /**
   * @触摸结束
   */
  touchend() {
      var that = this;
      that.setData({
          scale: that.data.scaleOld,
      });
  },
  onLoad: function () {
    var token = wx.getStorageSync('api_token')
    if(token!=undefined&&token!=null){
      this.setData({
        hasUserInfo: true
      })
    }
    this.setData({
      banner:[apiUrl+'/img/xcx/1.png',apiUrl+'/img/xcx/2.png',apiUrl+'/img/xcx/3.png']
    })
    this.getZhan();
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})
